'''
介绍:我的实验模块查询接口测试
作者:安雨杰
'''
from unittest import TestCase
from jsonpath import jsonpath
from parameterized import parameterized

from utils.reader import Reader
from utils.session import Session


# 查询
class QueryTest(TestCase):
    '''
    作者:安雨杰
    我的实验查询接口测试
    '''
    session = None
    header = None
    # 在测试类执行前
    @classmethod
    def setUpClass(cls) -> None:
        cls.session = Session.get_session()
        cls.header = Session.get_header()

    @classmethod
    def tearDownClass(cls) -> None:
        cls.session.close()

    @parameterized.expand(Reader.read_excel('cx.xlsx',min_row=1,max_row=92,min_col=1,max_col=5))
    # 定义参数, 实验编号, 状态, 类型, 实验名称, 预期结果
    def test_Query(self,experimentCode,status,experimentType,experimentName,expected_value):
        url = 'http://120.53.243.26:8009/api/experiment/findPage'
        # 请求数据
        data = {
                "pageNumber":0,
                "pageSize":10,
                "pageOrder":[],
                "searchDto":{
                            "includeSea":"",
                            "deptSysCodeSea":"",
                            "deptCasCodeSea":"",
                            "deptNameSea":"",
                            "fromMenu":"",
                            "searchExample":{
                                            "experimentCode":experimentCode,
                                            "status":status,
                                            "experimentType":experimentType,
                                            "experimentName":experimentName
                                            }
                            }
                }
        # 发送请求
        resp = self.session.post(url, json=data,headers=Session.get_header())
        # 打印状态码
        print(resp.status_code)
        # 断言状态码
        self.assertEqual(200, resp.status_code)
        # 将响应正文中的字符串转换为json类型的数据
        resp_data = resp.json()
        # 获取json数据中的content的值
        result = jsonpath(resp_data, '$..content')
        # 获取值中的数据
        result = result[0]
        # 根据列表中的预期值与实际值进行对比断言
        if expected_value == '非空列表':
            self.assertNotEqual(0, len(result))
        else:
            self.assertEqual(0, len(result))


if __name__ == '__main__':
    QueryTest()



